$(document).ready(function(){
	addComment();
});

//转换日期格式       
function changeDateFormat(cellval) {           
        if (cellval!=null) {               
        // var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));     
         var date = new Date(cellval);
         var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;               
         var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();   
         var year = date.getFullYear();
         var hour = date.getHours < 10 ? "0" + date.getHours() : date.getHours();
         var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
         var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
         return year + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;
  
         }  
 }

function addComment(){
	$("#postbtn").on("click",function(){
		var infoId = $(this).attr("data-Infoid");
		var comStr = $(".edui-body-container").children().text();
		alert("tian jia Comment"+comStr+"xinXi"+infoId);
		if (comStr == "" || comStr == null){
			alert("请输入评论内容！！！！");
		}else{
			$.ajax({
				url:"http://localhost:8080/Anime-sky/addComment",
				type:"POST",
				data:"infoId="+infoId+"&comContent="+comStr,
				success:function(result){
					if(result.code == 520){
						alert("传送数据到后台成功！！！！！！！！！！！");
						var com = result.extend.comment;
						var cdate = changeDateFormat(com.comDate);
						var htm1 = '<div class="rb" data-comid='+com.comId+' data-cominfoid='+com.infoId+'>';
						var htm2 = '<div class="rbsub"><div class="rbreply">回复</div><div class="rbdown">反对<span class="rbdownnum">(0)</span></div>';
						var htm3 = '<div class="rbup">赞<span class="rbupnum">(0)</span></div>';
						var htm4 = '<div class="rbtitle"> 客人<span class="rbnum">19</span> <span class="rbtime">'+cdate+'</span></div></div>';
						var htm5 = '<div class="clear"></div><div class="rbbody"><div class="rbarrow1"></div>';
						var htm6 = '<div class="rbarrow2" style="border-right-color:#91c0ed"></div><div class="rbicon">';
						var htm7 = '<div class="rbiconbox pie"><img width="64px" height="64px" src="http://static.missevan.com/avatars/201805/12/9cd0a0e58e24805a2f4ba1e4ac5755a0103005.jpg"></div>';
						var htm8 = '<div class="rbusername">'+com.user.userName+'</div></div><div class="rbvalueout">';
						var htm9 = '<div class="rbvalue pie" style="background-color:#91c0ed"><div class="rbcontent"><p>'+com.comContent+'</p></div>';
						var htma ='</div></div></div></div><div class="clear"></div>';
						var chtml =htm1 + htm2 + htm3 + htm4 + htm5 + htm6 + htm7 + htm8 + htm9 + htma;
						$("#leftreplylist").children(".rb").first().before(chtml);
						var comStr = $(".edui-body-container").children().text("");
					}
				}
			});
			
		}
	});
	
}